#include "delete_good.h"
#include "ui_delete_good.h"
#include "mainwindow.h"
#include "main.h"
#include <string>
#include <cstring>
#include "del_suc.h"
#include "notfound.h"
#include "null_database.h"
delete_good::delete_good(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::delete_good)
{
    ui->setupUi(this);
}

delete_good::~delete_good()
{
    delete ui;
}

void delete_good::on_buttonBox_accepted()
{
    std::string g_id = ui->lineEdit->text().toStdString();
    const char *del_id = g_id.c_str();
    goods_info *item=NULL;
    item = g_first;
    if(!strcmp(g_first->good_id, del_id)){
        g_first = g_first->next;
        delete item;
        del_suc *del_succ;
        del_succ = new del_suc;
        del_succ->show();
    }else{
        if(!o_first->next){
            NULL_database *null_data;
            null_data = new NULL_database;
            null_data->show();
        }else{
            while(item->next->next&&strcmp(item->next->good_id, del_id)){
                item = item->next;
            }
            if(!strcmp(item->next->good_id, del_id)){
                     goods_info *del_item=item->next;
                     item->next = item->next->next;
                     delete del_item;
                     del_suc *del_succ;
                     del_succ = new del_suc;
                     del_succ->show();
            }else{
                notfound *notf;
                notf = new notfound;
                notf->show();
            }
        }
    }
}
